using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class GiaoVien_CapNhapThongTinGiaoVien : System.Web.UI.Page
{
    GiaoVienBUS gv = new GiaoVienBUS();
    GiaoVienDTO gvDto = new GiaoVienDTO();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindList();
        }
    }
    void BindList()
    {
        gvDto.MaGiaoVien = Session["MaGiaoVien"].ToString();
        if (gvDto.MaGiaoVien == null)
            Response.Redirect("DangNhap.aspx");
        ItemsList.DataSource = gv.LuanVan_GiaoVien(gvDto.MaGiaoVien);
        ItemsList.DataBind();
    }
    protected ArrayList LayMangBoMon()
    {
        BoMonBUS bmBus = new BoMonBUS();
        ArrayList mang = bmBus.LayMang_BoMon();
        mang.RemoveAt(0);
        return mang; 
    }
    protected void Cancel_Command(object source, DataListCommandEventArgs e)
    {
        // Set the EditItemIndex property to -1 to exit editing mode. Be sure
        // to rebind the DataList to the data source to refresh the control.
        ItemsList.EditItemIndex = -1;
        BindList();
    }
    protected void Edit_Command(object source, DataListCommandEventArgs e)
    {
        // Set the EditItemIndex property to the index of the item clicked
        // in the DataList control to enable editing for that item. Be sure
        // to rebind the DataList to the data source to refresh the control.
        ItemsList.EditItemIndex = e.Item.ItemIndex;

        BoMonBUS bmBus = new BoMonBUS();
        
        //ddl.DataSource = bmBus.LayMang_BoMon();
        //ddl.DataBind();        

        BindList();
    }
    protected void Update_Command(object source, DataListCommandEventArgs e)
    {
        // Retrieve the updated values from the selected item.
        
        gvDto.TenGiaoVien = ((TextBox)e.Item.FindControl("TenGiaoVien")).Text;
        gvDto.ChucDanh = ((TextBox)e.Item.FindControl("ChucDanh")).Text;
        gvDto.HocHam = ((TextBox)e.Item.FindControl("HocHam")).Text;

        gvDto.HocVi = ((TextBox)e.Item.FindControl("HocVi")).Text;
        gvDto.Email = ((TextBox)e.Item.FindControl("Email")).Text;
        gvDto.DienThoai = ((TextBox)e.Item.FindControl("DienThoai")).Text;
        gvDto.HuongNghienCuu = ((TextBox)e.Item.FindControl("HuongNghienCuu")).Text;
        gvDto.NoiCongTac = ((TextBox)e.Item.FindControl("NoiCongTac")).Text;
        DropDownList ddl = ((DropDownList)e.Item.FindControl("ddlBoMon"));
        gvDto.MaBoMon = int.Parse(ddl.SelectedValue.ToString());


        gvDto.MaGiaoVien = Session["MaGiaoVien"].ToString();
        gv.update(gvDto);
        ItemsList.EditItemIndex = -1;
        BindList();
    }
}
